<template>
	<view>
	<!-- 404页面 -->
        <view class="noData" v-if="netWorkType == 'none'"><noData @handle="refresh"></noData></view>
        <view v-if="netWorkType != 'none'">
			<view class="content">
				<view class="tip">
					<view class="title">重置密码</view>
					<view>
						验证码将发送到号码为“{{mobile}}”的手机上请输入验证码并创建新的密码
					</view>
				</view>
				<view class="temp">
					<view class="temp-box">
						<view :class="code_val?'input-row input-hash':'input-row input-none'">
							<Input v-model="code_val" class="code_val" maxlength='6' placeholder="请输入验证码">
							        
								
							</Input>
							<span class="text" :style="send_time>0?'color:#959595':''" @tap.stop="sendMsg"   v-if="sendMessage">{{send_time>0?send_time+'s':''}}重新获取</span>
							<span class="text" @tap.stop="sendMsg" v-else  >获取验证码</span>
						</view>
						<view :class="pay_password?'input-row input-hash':'input-row input-none'">
							 <input v-model="pay_password" class="pwd" type="number" :password="password" maxlength='6' placeholder="新的密码">						        
								
							</input>
							<text class="text iconfont"  @tap.stop="showStatus()" >{{showpwd?'&#xe63b;':'&#xe63c;'}}</text>
							<!-- <span class="text" @tap.stop="sendMsg" v-else  >获取验证码</span> -->
						</view>
						<view :class="repay_password?'input-row input-hash':'input-row input-none'" >
							 <Input v-model="repay_password" class="pwd" maxlength='6' type="number"  :password="password" placeholder="确认密码">
							        
								
							</Input>
							<text class="text iconfont"  @tap.stop="showStatus()" >{{showpwd?'&#xe63b;':'&#xe63c;'}}</text>
						</view>
						
						<view class="  btn-set" @tap.stop='setPwd'>
							更改密码
						</view>
					</view>
					
					
					
				</view>
				
				
			</view>
		
			
		</view>
		
	</view>
</template>

<script>
	import uniPopup from '@/components/uni-popup/uni-popup.vue'
	// import tuiButton from "@/components/button/button"
	import { mapGetters } from 'vuex';
	export default {
		components:{
			// tuiButton
			uniPopup
		},
		data() {
			return {
				data:{
					list:""
				},
				mobile:'',
				tel:'',
				hasLogin:false,
				code_len: 6, // 验证码长度
				code_val: '', // 验证码的值
				is_focus: false,
				sendMessage:false, //是否以发送短信
				pay_password:'',
				repay_password:'',
				send_time:0,
				showpwd:false,
				password:true,//input类型是否为密码
				successTime:'',//倒计时
			};
		},
		computed: {
            ...mapGetters(['netWorkType','loginStatus'])    
        },
		onShow:function() {
			let _this=this;
			_this.getList()
		},
		methods:{
			// 刷新的方法
			refresh(){
			   window.addEventListener('pageshow', this.onShow);     
			},
			getList(){
				let _this = this
				// console.log(123)
				let data={}
				var opt = {
					url: '/user/getBusiness',
					data:data,
					success: function(res) {
						// console.log(res)
						if (res.status == 1) {
							_this.mobile = res.data.mobile
							_this.tel = res.data.tel
							
						} else {
				
						}
				
					}
				};
				_this.$service.GetApi(opt)
			},
			goBack(){
			   uni.navigateBack({ delta: 1 })
			 },
			 showStatus(){
				 this.showpwd = !this.showpwd
				 this.password =!this.showpwd
			 },
			
			sendMsg(){
				let _this = this
				if(_this.send_time>0){
					uni.showToast({
						icon:'none',
						title:'短时间内不能发送短信'
					})
					return ;
				}
				_this.sendMessage = true
				_this.send_time = 60
				_this.successTime = setInterval(() => {
					
					_this.send_time =_this.send_time-1
					console.log('**',_this.send_time)
					
					if(_this.send_time <=0){
						clearInterval(_this.successTime);
						_this.successTime = '';
					}
				}, 1000) 
				return ;
				// console.log(123)
				let data = {
					mobile:_this.tel,
					tpl_type:'business',
					option_type:'mb_business_resetpaypwd'
				}
				var opt = {
					url: '/Sms/getVertify',
					data:data,
					success: function(res) {
						//console.log(res)
						if (res.status == 1) {
							
							uni.showToast({
								icon:'none',
								title:'短信已发送成功,请注意接收'
							})
						} else {
				
						}
				
					}
				};
				_this.$service.GetApi(opt)
			},
			setPwd(){
				let _this = this
				if(_this.code_val == ''){
					uni.showToast({
						icon:'error',
						title:'请输入验证码！'
					})
					return ;
				}
				if(_this.pay_password ==''){
					uni.showToast({
						icon:'error',
						title:'请输入密码'
					})
					return ;
				}
				if(_this.pay_password !=_this.repay_password){
					uni.showToast({
						icon:'error',
						title:'两次密码输入不一致'
					})
					return ;
				}
				
				let data = {
					mobile:_this.tel,
					code_val:_this.code_val,
					pay_password:_this.pay_password,
					repay_password:_this.repay_password
				}
				var opt = {
					url: '/user/setPayPassword',
					data:data,
					success: function(res) {
						//console.log(res)
						if (res.status == 1) {
							uni.showToast({
								icon:'none',
								title:'操作成功'
							})
							_this.goBack();
						} else {
							uni.showToast({
								icon:'error',
								title:'修改失败'
							})
						}
				
					}
				};
				_this.$service.GetApi(opt)
			},
			
			
			setCode(e) {
				this.code_val = e.detail.value;
			},
			onCode() {			
				this.is_focus = true;
			},
			blurCode() {
				this.is_focus = false;
			},
			
			
		}
			
	}
</script>
<style scoped lang="scss">
	@import 'PayPassword.scss';
</style>

